package com.example.englishstudy.util

import android.util.Log
import com.example.englishstudy.constance.Constance
import com.example.englishstudy.TranslateEntity
import com.example.zhaojianxu.signin.common.http.HttpUtil
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/**
 * create by @zhaojianxu on 2019/2/14
 */
object TranslateUtil{
    fun translate(q: String, to: String){
        val hashMd5 = ComputeUtil.encode("${Constance.APP_ID}${q}${Constance.SALT}${Constance.KEY}")

        HttpUtil.instance.getEnglishApi()?.translate("${q}", "auto", to, Constance.APP_ID, 1, hashMd5)?.enqueue(object :
            Callback<TranslateEntity> {
            override fun onFailure(call: Call<TranslateEntity>, t: Throwable) {
                Log.d("TAGGG", "${t.message}")
            }

            override fun onResponse(call: Call<TranslateEntity>, response: Response<TranslateEntity>) {
                Log.d("TAGGG", "${response.body()?.trans_result?.firstOrNull()?.dst}")
            }

        })
    }
}